#ifndef OBJECT_H
#define OBJECT_H

#include <string>
#include <functional>
#include <chrono>
#include <mutex>

struct Tick{
    std::string instId; // 交易品种名称
    uint64_t timestamp; // 13位，精确到毫秒的时间
    double lastPrice;
    double volumn;
    double turnover;
};

class Bar{
public:
    std::string instId; // 交易品种名称
    uint64_t timestamp; // 13位，精确到毫秒的时间
    double open;
    double high;
    double low;
    double close;
    double volumn;
    double turnover;
    double total_ask_volumn;
    double total_bid_volumn;
    bool nodata;

    Bar();

    void update(double price,double volumn,double turnover);
    void reset();

private:
    std::mutex mtx;
};

class BarGenerator{
public:   
    Bar bar;
    BarGenerator(std::string instId,uint64_t period_ms);
    void generateBar(const Tick& tick);

private:
    std::string instId;
    uint64_t period_ms;
    uint64_t lastTime = 0;
};


struct Order{
    std::string symbol;
    std::string newClientOrderId;
    std::string side;                  // 枚举 ["SELL","BUY"]
    std::string type;                  // 枚举 ["LIMIT","MARKET"]
    double quantity;                   // 交易量
    std::string sQuantity;             // 字符串交易量
    double price;                      // 价格
    std::string sPrice;                // 字符串价格
    uint64_t timestamp;
    std::string timeInForce = "GTC";   // 限价需要有，FOK(fill or kill)
    uint64_t recvWindow = 5000;
};


struct Trade{
    std::string symbol; 
    std::string newClientOrderId;
    std::string side;                // 枚举 ["SELL","BUY"]
    double orderQuantity;            // 订单数量
    std::string status;              // 订单状态 [NEW,PARTIALLY_FILLED,FILLED]
    double volume;                   // 订单累计成交量
};


// 仅维护账户中 USDT 的信息
struct Account{               
    std::string symbol;       // 资产名称
    double walletBalance;     // 钱包余额
    double availableBalance;  // 除去逐仓仓位保证金的钱包余额
    double balanceChange;     // 除去盈亏与交易手续费以外的钱包余额改变量
};


// BOTH 持仓模式，正负仓位
struct Position{
    std::string symbol;       // 交易对
    double positionAmount;    // 仓位
}; 

#endif // OBJECT_H